/*
 * ColorizedTableCellRenderer.java
 */
package org.owasp.scrubbr.db.report;

import java.awt.Component;
import java.awt.Color;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class ColorizedTableCellRenderer extends DefaultTableCellRenderer  {

    public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) 
    {
        
        //convert to Model to get proper cell
        column = table.convertColumnIndexToModel(column);        
        
        Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        
        DBTableModel db = (DBTableModel) table.getModel();
        
        if ( row == table.getSelectedRow() && column == table.convertColumnIndexToModel(table.getSelectedColumn()) ) {
            
            cell.setBackground(Color.BLUE);
            
        } else if ( db.getTable().getTaintedRows().get(row).getAllTuples().get(column).isTainted() ) { 
            
           cell.setBackground( Color.pink );

        } else {
            
           cell.setBackground( Color.green );
           
        }
        
        return cell;
    }
}
